/*
	separate_rent_n_mortgage.do
	
		This code spearates rents from mortgage payments. In XXXX they are bundled
		together in category 1207
		
*/


***********************************************
* Start of filter
***********************************************

g lower_desc = lower(genericXXXXdescription)

g mortgage_flag = 0
replace mortgage_flag = 1 if inferredcategoryid == 1207 & ((strpos(lower_desc, "mortgage") ///
														| strpos(lower_desc, "mtg") ///
														| strpos(lower_desc, "mt") ///
														| strpos(lower_desc, "mrtg") ///
														| strpos(lower_desc, "mortg") ///
														| strpos(lower_desc, "mortgag") ///
														| strpos(lower_desc, "loan") ///
														| strpos(lower_desc, "debt") ///
														| strpos(lower_desc, "funding") ///
														| strpos(lower_desc, "fundin")) ///
														| ((regexm(lower_desc, "bank") ///
														| regexm(lower_desc, "fargo") ///
														| regexm(lower_desc, "us ba") ///
														| regexm(lower_desc, "chase") ///
														| regexm(lower_desc, "suntrust") ///
														| regexm(lower_desc, "1st nat") ///
														| regexm(lower_desc, "fnb alaska") ///
														| regexm(lower_desc, "citicorp") ///
														| regexm(lower_desc, "spirit") ///
														| regexm(lower_desc, "spirits of alaska") ///
														| regexm(lower_desc, "capital one") ///
														| regexm(lower_desc, "flagstar") ///
														| regexm(lower_desc, "morgan") ///
														| regexm(lower_desc, "finan") ///
														| regexm(lower_desc, "financial") ///
														| regexm(lower_desc, "fnc ins") ///
														| strpos(lower_desc, "fcu") ///
														| strpos(lower_desc, "financial")) ///
														& (!strpos(lower_desc, "withdrawal") & !strpos(lower_desc, "transfer"))))
														
replace mortgage_flag = 1 if inferredcategoryid == 20 & (strpos(lower_desc, "mortgage") ///
														| strpos(lower_desc, "mtg") ///
														| strpos(lower_desc, "mrtg") ///
														| strpos(lower_desc, "mortg") ///
														| strpos(lower_desc, "mortgag"))
														
														
//all the transactions in category 1207 get a one if the user was recognized
//to have a mortgage
bys userid: egen foo = max(mortgage_flag)
replace mortgage_flag = 1 if foo == 1 & inferredcategoryid == 1207
lab var mortgage_flag "potential mortgage payment; category 1207"
drop foo

generate rent_flag = (mortgage_flag == 0 & inferredcategoryid == 1207)
lab var  rent_flag "potential rent payment; category 1207"

drop lower_desc
